package com.lagou.edu.utils;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

public class pathutile {
    //获取指定包下的所有类名
    /**
     * 获取类加载器
     */
    public static ClassLoader getClassLoader() {
        return Thread.currentThread().getContextClassLoader();
    }

    //获取指定包下的所有类名
    public static Set<String> getClassSetStr(String packageName) throws IOException {
        Set<String> strings = new HashSet<>();

        Enumeration<URL> paths = getClassLoader().getResources(packageName.replace(".", "/"));

        while (paths.hasMoreElements()) {
            URL path = paths.nextElement();
            if (path != null) {
                String protocol = path.getProtocol();
                if (protocol.equals("file")) {
                    String packagePath = path.getPath().replaceAll("%20", " ");
                    strings.add(packagePath);
                }
            }
        }
        return strings;

    }

}
